package com.j1903.contorller;
import com.j1903.annotation.PassJwt;
import com.j1903.bean.Lunbo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.j1903.bean.Teoo;
import com.j1903.util.JsonResult;
import javax.annotation.Resource;
import com.j1903.service.TeooService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fjj
 * @since 2021-12-15
 */
@RestController
@RequestMapping("/j1903/teoo")
public class TeooController {
    @Resource
    private TeooService teooService;
    @RequestMapping("/add")
    @PassJwt
    public JsonResult add(@RequestBody Teoo obj)
    {
    teooService.save(obj);
        return new JsonResult(200,"添加成功",obj.getId());
    }
    @RequestMapping("/deleted")
    @PassJwt
    public JsonResult Delete(@RequestBody Long id){
        Boolean hint=teooService.removeById(id);
        if(hint)
        {
        return new JsonResult(200,"删除成功");
        }else
        {
        return new JsonResult(500,"删除失败");
        }

    }
    @RequestMapping("/update")
    @PassJwt
    public JsonResult Upd(@RequestBody Teoo obj){
        Boolean hint=teooService.saveOrUpdate(obj);
        if(hint)
        {
        return new JsonResult(200,"修改成功");
        }else
        {
        return new JsonResult(500,"修改失败");
        }

    }
    @RequestMapping("/list")
    @PassJwt
    public JsonResult list1(@RequestBody Teoo obj){
        List<Teoo> list=teooService.lists(obj);
        return new JsonResult(200,"查询成功",list);
    }
    @RequestMapping("/page/{curPage}/{pageRecords}")
    @PassJwt
    public JsonResult list2(@RequestBody Teoo obj,
        @PathVariable int curPage,
        @PathVariable int pageRecords
        ){
        IPage<Teoo> ipage=new Page<>(curPage,pageRecords);
        IPage<Teoo> page=teooService.pages(ipage,obj);
        return new JsonResult(200,"查询成功",page);
        }

}

